<template>
	<view class="content">
		<view class="info-box" >
			<image class="logo" src="../../static/logo.png"></image>
			<view class="appLogin">
				<view >
					<view class="userIphones flex padd-26 border_bottom_ccc">
						<u-input type="text" color="rgba(0,0,0,0.85);" placeholder="请输入账号" border="none"
							v-model="mobile">
								<u--text
									text="账号:"
									slot="prefix"
									margin="0 3px 0 0"
									type="tips"
								></u--text>
							</u-input>
					</view>
					<view class="userCode flex between padd-26 border_bottom_ccc">
						<u-input :password="true" placeholder="请输入密码"  color="rgba(0,0,0,0.85);"
							 border="none" v-model="code">
								<u--text
									text="密码:"
									slot="prefix"
									margin="0 3px 0 0"
									type="tips"
								></u--text>
							</u-input>
					</view>
					<view @click="appLoginBtn" class="loginBtn">
						<view class="loginText">登录</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				topHeight: '',
				code: '',
				mobile: '',
				platfrom:'app',
				faq_id:'',
				rand:''
			}
		},
		onLoad(op) {
			console.log(op,'..........')
			if(op&&op.platfrom&&op.platfrom == 'wx'){
				this.platfrom = op.platfrom
				this.rand = op.rand
				this.faq_id = op.faq_id
				uni.showLoading()
				this.appLoginBtn()
			}
		},
		onShow() {
			console.log('onshow')
			let mobile = uni.getStorageSync('mobile')
			let pwd = uni.getStorageSync('pwd')
			this.mobile = mobile
			this.code = pwd
			if(mobile&&pwd){
				uni.showLoading()
				this.appLoginBtn()
			}
		},
		mounted() {
			
		},
		methods: {
			appLoginBtn() {
				uni.removeStorageSync('token')
				uni.removeStorageSync('userInfo')
				if(!this.mobile&&this.platfrom!='wx') {
					return uni.showToast({
						title:'请输入账号！',
						icon:'none'
					})
				} 
				if(!this.code&&this.platfrom!='wx') {
					return uni.showToast({
						title:'请输入密码！',
						icon:'none'
					})
				} 
				let param = {
					username:'',
					password:'',
				}
				if(this.platfrom!='wx'){
					param['username'] = this.mobile
					param['password'] = this.code
				}else{
					param['rand'] = this.rand
					param['platfrom'] = this.platfrom
					param['faq_id'] = this.faq_id
				}
				this.$login.login(param).then(res=>{
					if(res.status == 200){
						uni.setStorageSync('token',res.token)
						uni.setStorageSync('userInfo',res.data)
						if(this.platfrom!='wx'){
							uni.setStorageSync('mobile',this.mobile)
							uni.setStorageSync('pwd',this.code)
							uni.reLaunch({
								url:'/pages/index/index'
							})
						}else{
							uni.reLaunch({
								url:'/pages/index/questionDetails?pid='+this.faq_id+'&platfrom='+this.platfrom
							})
						}
						
					}
					uni.hideLoading()
				})
				.catch(err=>{
					uni.hideLoading()
				})
				
				// that.$utils.toPage({
				// 	url: '/pages/home/index',
				// 	type: 'switchTab'
				// })
				// let that = this
				// let familyInfo = uni.getStorageSync('familyInfo')
				// let token = uni.getStorageSync('token')
			},
			
		}

	}
</script>

<style lang="scss" scoped>
	.content {
		background-image: url('https://bbfnimage.oss-cn-shanghai.aliyuncs.com/bbyeIconImage/img/' + 'bg.png'); // 小程序需要切换这种bg模式
		background-size: 100% 100%;
		background-repeat: no-repeat;
		box-sizing: border-box;

		.loginBtn {
			padding: 0 72rpx;
			width: 100%;
			box-sizing: border-box;
			height: 88rpx;
			background: linear-gradient(265deg, #FF8C8E 0%, #FF2E2D 54%);
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			opacity: 1;
			margin-top: 60rpx;

			.loginText {
				width: 100%;
				line-height: 88rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}
		}

		.login-type {
			width: 100%;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			font-size: 28rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			color: #858F99;
		}

		.info-box {
			display: flex;
			flex-direction: column;
			align-items: center;
			box-sizing: border-box;
			padding-top: calc(30% + var(--status-bar-height));

			.top-btn {
				z-index: 999900;
				width: 100%;
				padding: 0 32rpx;
				box-sizing: border-box;
				text-align: right;
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				color: #858F99;
			}

			.logo {
				width: 134rpx;
				height: 134rpx;
				margin-bottom: 64rpx;
			}

			.font-info {
				text-align: center;
				color: rgba(0, 0, 0, 0.85);

				.title {
					font-size: 68rpx;
					font-family: PingFang SC-Semibold, PingFang SC;
					font-weight: 600;
				}

				.tips {
					font-size: 34rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
				}
			}

			.appLogin {
				width: 100%;
				padding: 0 72rpx;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
			}

			.padd-26 {
				padding: 26rpx 12rpx 26rpx;
			}

			.border_bottom_ccc {
				border-bottom: 2rpx solid rgba(0, 0, 0, 0.15);
			}

			.ruleText {
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #FE0303;
			}

			.wechat-info {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 568rpx;
				height: 88rpx;
				background: #2FC25B;
				border-radius: 44rpx;
				margin-top: 200rpx;
				color: #fff;
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;

				.wechat {
					width: 48rpx;
					height: 48rpx;
					margin-right: 16rpx;
				}
			}

			.getPhone {
				width: 568rpx;
				height: 88rpx;
				background: #fff;
				border-radius: 44rpx;
				color: rgba(0, 0, 0, 0.45);
				line-height: 88rpx;
				border: 2rpx solid rgba(0, 0, 0, 0.45);
				margin-top: 20rpx;
				font-size: 24rpx;
			}

			.btm-info {
				display: flex;
				align-items: center;
				justify-content: center;
				position: fixed;
				box-sizing: border-box;
				width: 100%;
				// padding: 0 72rpx;
				text-align: center;
				// left: 50%;
				// transform: translateX(-50%);
				bottom: 0;
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				color: rgba(0, 0, 0, 0.45);
				padding-bottom: 62rpx;
			}
		}
	}
</style>